package com.basic.business.utils;

import com.basic.business.common.execption.BusinessException;
import org.apache.commons.lang3.StringUtils;

/**
 * 加密工具
 */
public class AESUtil {
    //加密字符串
    private static final String AES_KEY = "huagebiancheng12";

    public static void main(String[] args) {
        String s = encodeByAES("YWRtaW4=");
        System.out.println("s = " + s);
    }

    /**
     * AES 解密
     *
     * @param str
     * @return
     */
    public static String decodeByAES(String str) {
        try {
            if(StringUtils.isEmpty(str)){
                return str;
            }
            return AESUtils.decrypt(str, AES_KEY);
        } catch (Exception e) {
            throw new BusinessException("解密失败", e);
        }
    }

    /**
     * 加密
     *
     * @param str
     * @return
     */
    public static String encodeByAES(String str) {
        try {
            if(StringUtils.isEmpty(str)){
                return str;
            }
            return AESUtils.encrypt(str, AES_KEY);
        } catch (Exception e) {
            throw new BusinessException("解密失败", e);
        }

    }
}